package com.book.bookmanager.service;


import com.book.bookmanager.dao.bookDao;
import com.book.bookmanager.pojo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class bookServiceImpl implements bookService {
	@Autowired
	private bookDao bd;

	@Override
	public List<Book> queryAll() {
		return bd.selectAll();
	}

	@Override
	public void removeById(Integer id) {
		try {
			bd.deleteById(id);
		} catch (Exception e) {
			throw new RuntimeException("删除错误");
		}
	}

	@Override
	public void addBook(Book book) {
		try {
			bd.insertBook(book);
		} catch (Exception e) {
			throw new RuntimeException("插入错误");
		}
	}

	@Override
	public Book queryById(Integer id) {
		return bd.selectById(id);
	}

	@Override
	public void changeBook(Book book) {
		try {
			bd.updateBook(book);
		} catch (Exception e) {
			throw new RuntimeException("插入错误");
		}
	}
	@Override
	public void addPhoto(Book book){
		try {
			bd.addPhoto(book);
		}catch (Exception e){
			throw new RuntimeException("图片错误");
		}
	}
}
